package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.group_all_details;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.strategy.GroupBean;
import com.wangjiyuan.giftshuo.config.classify.ClassifyConstant;

import java.util.ArrayList;
import java.util.List;

/**
 *品类、风格、对象 点击查看全部的页面
 */

public class StrategyDetailsActivity extends AppCompatActivity {
    private Toolbar toolbarStrDet;
    private TextView textViewStrDet;

    private RecyclerView mRecyclerView;
    private Context mContext=this;
    private StrDetAdapter strDetAdapter;
    private List<GroupBean.DataBean.ChannelGroupsBean.ChannelsBean> channelsList=new ArrayList<>();

    private String titleName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_strategy);
//        获得Groups对象
        getGroups();
        initView();
    }

    private void initView() {
        textViewStrDet= (TextView) findViewById(R.id.textView_strategy_title);
        textViewStrDet.setText(titleName);

        toolbarStrDet= (Toolbar) findViewById(R.id.toolBar_strategy_details);
//        设置titile，居中
        initToolBar();

        mRecyclerView= (RecyclerView) findViewById(R.id.recyclerView_strategy_Details);
        mRecyclerView.setHasFixedSize(true);
        GridLayoutManager gridLayoutManager=new GridLayoutManager(mContext,2, OrientationHelper.VERTICAL,false);
        strDetAdapter=new StrDetAdapter(mContext,channelsList);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setAdapter(strDetAdapter);
    }

    private void initToolBar() {
        toolbarStrDet.setTitle("");
        setSupportActionBar(toolbarStrDet);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void getGroups() {
        Intent intent = getIntent();
        Bundle bundleExtra = intent.getExtras();
        GroupBean.DataBean.ChannelGroupsBean groups = (GroupBean.DataBean.ChannelGroupsBean) bundleExtra.get(ClassifyConstant.GROUPS);
        titleName = groups.getName();
        List<GroupBean.DataBean.ChannelGroupsBean.ChannelsBean> channels = groups.getChannels();
        channelsList.addAll(channels);
    }
}
